package com.tts.hbdao;

import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.tts.hbentity.Scenery;

/**
 * Data access object (DAO) for domain model class Scenery.
 * 
 * @see com.tts.hbentity.Scenery
 * @author MyEclipse Persistence Tools
 */

public class SceneryDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(SceneryDAO.class);
	// property constants
	public static final String SCENERY_NAME = "sceneryName";
	public static final String SCENERY_AREA = "sceneryArea";
	public static final String SCENERY_ADDRESS = "sceneryAddress";
	public static final String SCENERY_TEL = "sceneryTel";
	public static final String SCENERY_PRICE = "sceneryPrice";
	public static final String SCENERY_INTRODUCE = "sceneryIntroduce";
	public static final String SCENERY_PIC = "sceneryPic";
	public static final String SCENERY_LEVEL = "sceneryLevel";

	public void save(Scenery transientInstance) {
		log.debug("saving Scenery instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Scenery persistentInstance) {
		log.debug("deleting Scenery instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Scenery findById(java.lang.Integer id) {
		log.debug("getting Scenery instance with id: " + id);
		try {
			Scenery instance = (Scenery) getSession().get(
					"com.tts.hbdao.Scenery", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Scenery instance) {
		log.debug("finding Scenery instance by example");
		try {
			List results = getSession().createCriteria("com.tts.hbdao.Scenery")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Scenery instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Scenery as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findBySceneryName(Object sceneryName) {
		return findByProperty(SCENERY_NAME, sceneryName);
	}

	public List findBySceneryArea(Object sceneryArea) {
		return findByProperty(SCENERY_AREA, sceneryArea);
	}

	public List findBySceneryAddress(Object sceneryAddress) {
		return findByProperty(SCENERY_ADDRESS, sceneryAddress);
	}

	public List findBySceneryTel(Object sceneryTel) {
		return findByProperty(SCENERY_TEL, sceneryTel);
	}

	public List findBySceneryPrice(Object sceneryPrice) {
		return findByProperty(SCENERY_PRICE, sceneryPrice);
	}

	public List findBySceneryIntroduce(Object sceneryIntroduce) {
		return findByProperty(SCENERY_INTRODUCE, sceneryIntroduce);
	}

	public List findBySceneryPic(Object sceneryPic) {
		return findByProperty(SCENERY_PIC, sceneryPic);
	}

	public List findBySceneryLevel(Object sceneryLevel) {
		return findByProperty(SCENERY_LEVEL, sceneryLevel);
	}

	public List findAll() {
		log.debug("finding all Scenery instances");
		try {
			String queryString = "from Scenery";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Scenery merge(Scenery detachedInstance) {
		log.debug("merging Scenery instance");
		try {
			Scenery result = (Scenery) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Scenery instance) {
		log.debug("attaching dirty Scenery instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Scenery instance) {
		log.debug("attaching clean Scenery instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}